package com.chookss.home.gallery;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chookss.R;
import com.chookss.Urls;
import com.chookss.home.entity.GalleryListEntity;
import com.chookss.tools.GlideUtils;
import com.chookss.tools.MyToast;
import com.chookss.tools.NavigationTools;
import com.chookss.tools.SignUtils2;
import com.chookss.tools.Utils;
import com.chookss.tools.okgoconfig.MyHttpRequest;
import com.chookss.tools.okgoconfig.callback.ObserverCallback;
import com.chookss.tools.okgoconfig.model.LzyResponse;
import com.google.gson.reflect.TypeToken;
import com.lvgroup.hospital.base.BaseAct;

import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class GalleryDetailActivity extends BaseAct {
    @BindView(R.id.common_title_txt)
    TextView commonTitleTxt;
    @BindView(R.id.iv)
    ImageView iv;
    @BindView(R.id.tvName)
    TextView tvName;
    @BindView(R.id.tvSize)
    TextView tvSize;
    @BindView(R.id.tvPeople)
    TextView tvPeople;
    @BindView(R.id.tvTime)
    TextView tvTime;
    @BindView(R.id.tvProvider)
    TextView tvProvider;
    @BindView(R.id.tvDirectory)
    TextView tvDirectory;
    @BindView(R.id.tvKeywords)
    TextView tvKeywords;
    @BindView(R.id.tvLabel)
    TextView tvLabel;
    @BindView(R.id.tvLocation)
    TextView tvLocation;
    @BindView(R.id.tvOriginal)
    TextView tvOriginal;
    @BindView(R.id.tvShares)
    TextView tvShares;
    @BindView(R.id.tvReads)
    TextView tvReads;
    @BindView(R.id.tvShareNum)
    TextView tvShareNum;
    private String imageCode;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gallery_detail);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        initState3();
        commonTitleTxt.setText("详细信息");
        NavigationTools.saveUseRecord(this, "1", "26");
        imageCode = getIntent().getStringExtra("imageCode");
        getData();
        showLoading();
    }

    private void getData() {
        Map<String, String> allmap = new HashMap<>();
        allmap.put("imageCode", imageCode);
        MyHttpRequest.getDefault().getRequest(new TypeToken<LzyResponse<GalleryListEntity.ImagePathListBean>>() {
        }.getType(), null, Urls.getImageDetail, SignUtils2.makeSignStr(allmap), false, new ObserverCallback<GalleryListEntity.ImagePathListBean>() {
            @Override
            public void onSuccess(GalleryListEntity.ImagePathListBean data) {
                dismissLoading();
                if (data != null) {
                    if (tvName == null) {
                        return;
                    }
                    tvName.setText(data.getImageTitle());
                    if(Utils.isNull(data.getImageWidth())||Utils.isNull(data.getImageLength())){
                        if(Utils.isNull(data.getImageSize())){
                            tvSize.setVisibility(View.GONE);
                        }else{
                            tvSize.setText(Utils.changeKM(data.getImageSize()));
                        }
                    }else{
                        if(Utils.isNull(data.getImageSize())){
                            tvSize.setText(data.getImageWidth()+"×"+data.getImageLength());
                        }else{
                            tvSize.setText(Utils.changeKM(data.getImageSize())+"  "+data.getImageWidth()+"×"+data.getImageLength());
                        }
                    }

                    tvPeople.setText(data.getCreateEmployeeName());
                    tvTime.setText(data.getCreateTime());
                    if (Utils.isNull(data.getProvideEmployeeName())) {
                        tvProvider.setText("无");
                    } else {
                        tvProvider.setText(data.getProvideEmployeeName());
                    }
                    if (Utils.isNull(data.getCatalogNames())) {
                        tvDirectory.setText("无");
                    } else {
                        tvDirectory.setText(data.getCatalogNames());
                    }
                    if (Utils.isNull(data.getImageKeyWord())) {
                        tvKeywords.setText("无");
                    } else {
                        tvKeywords.setText(data.getImageKeyWord());
                    }
                    if (Utils.isNull(data.getTagNames())) {
                        tvLabel.setText("无");
                    } else {
                        tvLabel.setText(data.getTagNames());
                    }
                    if (Utils.isNull(data.getImageUploadLocation())) {
                        tvLocation.setText("无");
                    } else {
                        tvLocation.setText(data.getImageUploadLocation());
                    }
                    if ("0".equals(data.getOriginal())) {
                        tvOriginal.setText("否");
                    } else {
                        tvOriginal.setText("是");
                    }
                    if ("0".equals(data.getShareFlag())) {
                        tvShares.setText("否");
                    } else {
                        tvShares.setText("是");
                    }
                    tvReads.setText(Utils.changeNumber(data.getViewNum()) + "");
                    tvShareNum.setText(Utils.changeNumber(data.getShareNum()) + "");
                    GlideUtils.loadCustomRound(GalleryDetailActivity.this, data.getImagePath(), iv, R.drawable.default_news,4);
                }
            }

            @Override
            public void onError(String errorMsg) {
                dismissLoading();
                MyToast.show(Utils.onErrorTips(errorMsg));
            }
        });
    }

    @OnClick(R.id.common_title_back)
    public void onClick() {
        finish();
    }

}
